package com.book.controller;

import com.book.dao.orderDao;
import com.book.po.fix;
import com.book.po.student;
import com.book.service.fixService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
@RequestMapping("/fix")
public class fixController {
    @Autowired
    private fixService fixService;
    @Autowired
    private com.book.dao.orderDao orderDao;

    @RequestMapping("/fix_select")
    public String book_select(RedirectAttributes  model, HttpSession session){
        String sid =((student)session.getAttribute("student")).getId();
        List<fix> fixes = fixService.fix_select(sid);
        if (fixes.size()>=1){
            model.addFlashAttribute("fixes",fixes);
            model.addFlashAttribute("msg","");
            return "redirect:/user/fix";
        }else {
            model.addFlashAttribute("msg","当前教室暂无报修记录！");
            return "redirect:/user/fix";
        }
    }

    @RequestMapping("/fix_insert")
    public String book_insert(RedirectAttributes  model, fix fix,String sid){
        fix.setSign("0");
        fix.setCount(1);
        fix.setSid(sid);
        String rid = orderDao.rid_select(sid);
        fix.setRid(rid);
        String msg = fixService.fix_insert(fix);

        model.addFlashAttribute("msg",msg);
        return "redirect:/user/fix";
    }
//
    @RequestMapping("/fix_count")
    public String book_update(RedirectAttributes  model,  int id){
        String msg = fixService.fix_count(id);
        model.addFlashAttribute("msg",msg);
        return "redirect:/user/fix";
    }
//
//    @RequestMapping("/book_delete")
//    public String book_delete(RedirectAttributes  model, Integer bookId){
//        String msg = bookService.book_delete(bookId);
//        model.addFlashAttribute("msg",msg);
//        return "redirect:/manage/bookManage";
//    }
}
